<script setup>
import { ref } from 'vue'
import {Download, Plus, Upload} from "@element-plus/icons-vue";
import useTable from "@/utils/useTable";
import { http } from "@/api";
import {useRouter} from "vue-router";
import {sentimentTemplateDownloadUrl} from "@/utils/common";
import {ElMessage} from "element-plus";
const router = useRouter()
/**
 * 搜索
 */

const dateRange = ref([])
const changeDate = (val) => {
  if (!val) {
    searchParams.value.startCreate = ''
    searchParams.value.endCreate = ''
    return
  }
  searchParams.value.startCreate = val[0] || ''
  searchParams.value.endCreate = val[1] || ''
}
/**
 * 表格
 * @type {Ref<UnwrapRef<*[]>>}
 */
const {
  searchParams,
  pageNo,
  pageSize,
  total,
  changePage,
  changeSize,
  dataSource,
  search,
  reset,
  openAdd,
  openView,
  openEdit,
  openDelete
} = useTable({
  requestFn: http.sentiment,
  routerPre: 'sentiment',
  params: {
    "endCreate": "",
    "heat": '',
    "startCreate": "",
    "title": ""
  },
})
const updateTableRow = (row) => {
  http.sentiment.updateIndex({
    id: row.id,
    serialNumber: row.serialNumber
  }).then(res => {
    ElMessage.success('排序成功')
    search()
  })
}
const rankSetting = () => {
  router.push({
    path: `/sentiment/rank`
  })
}
const downloadTemplate = () => {
  const link = document.createElement('a')
  link.style.display = 'none'
  link.href = sentimentTemplateDownloadUrl
  link.setAttribute('download', '舆情导入模板.xlsx')
  document.body.appendChild(link)
  link.click()
  document.body.removeChild(link)
}
const openUpload = (file) => {
  http.sentiment.import(file.file).then(res => {
    ElMessage.success('导入成功')
    search()
  })
}
</script>

<template>
  <PageMain title="舆情发布" is-back>
    <div class="table-box">
      <el-table :data="dataSource">
        <el-table-column label="舆情标题" prop="title"></el-table-column>
        <el-table-column label="发布时间" width="180px" prop="releaseTime">
        </el-table-column>
        <el-table-column label="点赞数" width="100px" prop="likeNum" />
        <el-table-column label="浏览数" width="100px" prop="browseNum" />
        <el-table-column label="转发数" width="100px" prop="forwardNum" />
        <el-table-column label="作者" prop="author" />
        <el-table-column label="舆情来源" prop="source" />
        <el-table-column label="热度" prop="heat"></el-table-column>

        <el-table-column label="排序" width="80px">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              <el-input placeholder="请输入排序" v-model="scope.row.serialNumber" type="number" @blur="updateTableRow(scope.row)"/>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          v-model:current-page="pageNo"
          v-model:page-size="pageSize"
          :page-sizes="[10, 50, 100, 200]"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="changeSize"
          @current-change="changePage"
      />

    </div>
  </PageMain>
</template>

<style scoped lang="scss">

</style>
